package kyssion.leetcode.num101_150;

import kyssion.leetcode.util.TreeNode;

public class code101_对称二叉树 {

    public static void main(String[] args) {
        TreeNode node = TreeNode.create(
                new int[]{
                        1, 2, 2, 3, 4, 4, 3
                }
        );
        System.out.println(new code101_对称二叉树().isSymmetric(node));
    }

    /**
     * 普通方法
     *
     * @param root
     * @return
     */
    public boolean isSymmetric(TreeNode root) {
        if (root == null) {
            return true;
        }
        return ans(root.left, root.right);
    }

    private boolean ans(TreeNode left, TreeNode right) {
        if (left == null && right == null) {
            return true;
        } else if (left == null || right == null) {
            return false;
        } else {
            if (left.val != right.val) {
                return false;
            } else {
                return ans(left.left, right.right) && ans(left.right, right.left);
            }
        }
    }

}
